# Contributor: Michał Polański <michal@polanski.me>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=usbguard
pkgver=1.1.2
pkgrel=8
pkgdesc="Software framework for implementing USB device authorization policies"
url="https://usbguard.github.io/"
license="GPL-2.0-or-later"
arch="all"
makedepends="
	abseil-cpp-dev
	asciidoc
	audit-dev
	catch2
	libcap-ng-dev
	libqb-dev
	libseccomp-dev
	libsodium-dev
	pegtl
	protobuf-dev
	"
checkdepends="coreutils"
subpackages="
	libusbguard:libs
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/USBGuard/usbguard/releases/download/usbguard-$pkgver/usbguard-$pkgver.tar.gz
	gcc13.patch
	usbguard.initd
	"

build() {
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--disable-static \
		--without-bundled-catch \
		--without-bundled-pegtl \
		--without-dbus \
		--without-polkit \
		--with-crypto-library=sodium
	make
}

check() {
	make check
}

package() {
	make install DESTDIR="$pkgdir"
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	install -Dm644 scripts/bash_completion/usbguard \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 scripts/usbguard-zsh-completion \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
03b6dd026a0fe6a7a055208f09a56e2cc86985570388e33fde08671b8aa2d60ea4a0e59505e9646ddf50f42f5b6310d1b230379f9c26ec99c7ca736f3b4ad850  usbguard-1.1.2.tar.gz
db5153bacfed442abbbb4bb4fc8250f6469a654600aa3eddb1dda3d5800a265099c9f6ff48e7987d8fd03d4f456cbd83a9012ea4e9983e753392149696f75f06  gcc13.patch
9d6752f08df0ba510fa02c0c9b55a92f063297653480c4d8863f87f159dc51449a34643e75af7619146e2e53c91d479be91ecc0c9adc0c764d037f4df466e534  usbguard.initd
"
